/**   
 * 项目名：化工企业安全生产信息化管理平台
 * 日期：    2020-03-01 23:14:00  
 * Copyright (c) 2015- -版权所有     
 */

package com.joysuch.wwyt.edu.controller;

import javax.validation.Valid;

import cn.zlg.common.springmvc.validate.constraints.NotNull;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.edu.bean.EduQuestionItemEditBean;
import com.joysuch.wwyt.edu.service.EduQuestionItemService;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "教育-题库管理")
@RequestMapping("/edu/question-item")
public class EduQuestionItemController {

    private static final Logger logger = LoggerFactory.getLogger(EduQuestionItemController.class);

    @Autowired
    private EduQuestionItemService eduQuestionItemService;

    @RequiresPermissions("edu:question:item:add")
    @RequestMapping("add")
    public Object add(@Valid @RequestBody EduQuestionItemEditBean entity) {
        eduQuestionItemService.add(entity);
        return ResultBean.success("");
    }

    @RequiresPermissions("edu:question:item:update")
    @RequestMapping("update")
    public Object update(@Valid @RequestBody EduQuestionItemEditBean entity) {
        if (entity.getId() == null) {
            return ResultBean.fail(102, "未指定主键");
        }
        eduQuestionItemService.update(entity);
        return ResultBean.success("");
    }

    @RequiresPermissions("edu:question:item:delete")
    @RequestMapping("delete")
    public Object delete(Long id) throws Exception {
        eduQuestionItemService.delete(id);
        return ResultBean.success("");
    }

  //  @RequiresPermissions("edu:question:item")
    @RequestMapping("get")
    public Object getById(@Valid @NotNull(field = "id") Long id) {
        return ResultBean.success(eduQuestionItemService.getById(id));
    }
}
